//
//  EvaluationVc.m
//  WY_Water
//
//  Created by wangyang on 2019/12/24.
//  Copyright © 2019 wangyang. All rights reserved.
//

#import "EvaluationVc.h"

@interface EvaluationVc ()<UITextViewDelegate>
@property (nonatomic,strong) UIScrollView  *WyScrollView;
@property (nonatomic,strong) UIView     *WyOneBackView;
@property (nonatomic,strong) UIView     *WyTwoBackView;

@end

@implementation EvaluationVc

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"评价一下 ";
     self.view.backgroundColor =  UIColorFromRGB(0xF5F7F9);
     self.navigationController.interactivePopGestureRecognizer.delegate = self;
    [self WyOneBackView];
    [self WyTwoBackView];
    [self initSetWyUI];
}
- (UIScrollView *)WyScrollView {
    
    if (!_WyScrollView) {
        _WyScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_WyScrollView];
        _WyScrollView.userInteractionEnabled = YES;
        _WyScrollView.showsVerticalScrollIndicator = NO;
        _WyScrollView.contentSize = CGSizeMake(WySCREENWIDTH, WySCREENHEIGHT*1);
        _WyScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_WyScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.mas_offset(0);
            
        }];
        if (@available(iOS 11.0, *)) {
            
            self.WyScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return _WyScrollView;
}
-(UIView *)WyTwoBackView

{
    
    if (!_WyTwoBackView) {
        
        _WyTwoBackView = [[UIView alloc] init];
        [self.WyScrollView addSubview:_WyTwoBackView];
        _WyTwoBackView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
        _WyTwoBackView.layer.shadowColor = [UIColor colorWithRed:8/255.0 green:6/255.0 blue:6/255.0 alpha:0.1].CGColor;
        _WyTwoBackView.layer.shadowOffset = CGSizeMake(0,2);
        _WyTwoBackView.layer.shadowOpacity = 1;
        _WyTwoBackView.layer.shadowRadius = 6;
        _WyTwoBackView.layer.cornerRadius = 10;
        [_WyTwoBackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-60, 100));
            make.top.mas_offset(20);
            make.centerX.mas_offset(0);
        }];
        
    }
    
    return _WyTwoBackView;
    
}
-(UIView *)WyOneBackView

{
    
    if (!_WyOneBackView) {
        
        _WyOneBackView = [[UIView alloc] init];
        [self.WyScrollView addSubview:_WyOneBackView];
        _WyOneBackView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
        _WyOneBackView.layer.shadowColor = [UIColor colorWithRed:8/255.0 green:6/255.0 blue:6/255.0 alpha:0.1].CGColor;
        _WyOneBackView.layer.shadowOffset = CGSizeMake(0,2);
        _WyOneBackView.layer.shadowOpacity = 1;
        _WyOneBackView.layer.shadowRadius = 6;
        _WyOneBackView.layer.cornerRadius = 10;
        [_WyOneBackView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-60, 150));
            make.top.equalTo(self.WyTwoBackView.bottom).offset(20);
            make.centerX.mas_offset(0);
        }];
        
    }
    
    return _WyOneBackView;
    
}



-(void)initSetWyUI{
    
    _TextView = [[UITextView alloc]init];
    [self.WyOneBackView addSubview:_TextView];
    _TextView.delegate = self;
    _TextView.text = @"请给商品打个分吧";
    _TextView.textColor  = UIColorFromRGB(0xCCCCCC);
    _TextView.editable = YES;
    _TextView.userInteractionEnabled = YES;
    _TextView.backgroundColor = [UIColor whiteColor];
    _TextView.font = [UIFont systemFontOfSize:16];
    [_TextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(WySCREENWIDTH-80, 130));
        make.top.mas_offset(BiLiWidth(10));
        make.centerX.equalTo(0);
    }];
    
    
    _ayiLabe = [UILabel labelWithContent:@"请给商品打个分吧" superView:self.WyTwoBackView textColor:[UIColor blackColor] font:[UIFont systemFontOfSize:16] textAlignment:NSTextAlignmentLeft];
    [_ayiLabe mas_makeConstraints:^(MASConstraintMaker *make) {
         make.size.equalTo(CGSizeMake(140, 20));
         make.top.mas_offset(BiLiWidth(10));
         make.left.mas_offset(10);
    }];
    
    for (int i = 0 ; i< 5; i++) {
           
           UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
           [self.WyTwoBackView addSubview:btn];
           [btn setBackgroundImage:[UIImage imageNamed:@"星星备份 4"] forState:UIControlStateNormal];
           [btn setBackgroundImage:[UIImage imageNamed:@"星星"] forState:UIControlStateSelected];
           [btn addTarget:self action:@selector(selector:) forControlEvents:UIControlEventTouchUpInside];
           btn.tag = i+10;
           if (btn.tag ==10) {
               btn.selected = YES;
           }
           [btn mas_makeConstraints:^(MASConstraintMaker *make) {
               make.size.equalTo(CGSizeMake(BiLiWidth(32), 32));
               make.top.equalTo(self.ayiLabe.bottom).offset(BiLiWidth(12));
               make.left.mas_offset(BiLiWidth(10)+46*i);
           }];
           
       }
    
    
      _SubmitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
       [self.view addSubview:_SubmitBtn];
       [_SubmitBtn setBackgroundColor:UIColorFromRGB(0xFADB14)];
       [_SubmitBtn setTitle:@"提交评价" forState:0];
        WyViewRadius(_SubmitBtn, BiLiWidth(8));
       [_SubmitBtn setTitleColor:[UIColor whiteColor] forState:0];
       [_SubmitBtn addTarget:self action:@selector(Submitselector) forControlEvents:UIControlEventTouchUpInside];
       [_SubmitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
           make.size.equalTo(CGSizeMake(WySCREENWIDTH-30, 45));
           make.top.equalTo(self.WyOneBackView.bottom).offset(BiLiWidth(40));
           make.centerX.mas_offset(0);
       }];
    
    
}
-(void)selector:(UIButton *)button{
    
    
    for (int i=0; i<=(int)button.tag-10; i++) {
        NSLog(@"%d",i);
        UIButton *btn = (UIButton *)[self.WyTwoBackView viewWithTag:i+10];
        btn.selected = YES;
    }
    
    for (int i=(int)button.tag-9; i<= 4; i++) {
        NSLog(@"----%d",i+10);
        UIButton *btn = (UIButton *)[self.WyTwoBackView viewWithTag:i+10];
        btn.selected = NO;
    }
    
}
-(void)Submitselector
{
    if (_TextView.text.length == 0) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"请输入内容"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                              handler:^(UIAlertAction * action) {
                                                                  //响应事件
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
        
    }
    else
    {
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"信息提示"
                                                                       message:@"感谢您的反馈"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                              handler:^(UIAlertAction * action) {
                                                                  
                                                                  //响应事件
                                                                  
                                                                  [self.navigationController popViewControllerAnimated:YES];
                                                                  NSLog(@"action = %@", action);
                                                              }];
        UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault
                                                             handler:^(UIAlertAction * action) {
                                                                 //响应事件
                                                                 NSLog(@"action = %@", action);
                                                             }];
        
        [alert addAction:defaultAction];
        [alert addAction:cancelAction];
        [self presentViewController:alert animated:YES completion:nil];
    }
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([_TextView.text isEqualToString:@"请给商品打个分吧"]) {
        _TextView.text = @"";
    }
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
